package com.smalls.redshoes.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolManager {
    public static ExecutorService cachePool = Executors.newFixedThreadPool(5);
    public static ExecutorService savePool;

    public static void startThread() {
        cachePool = Executors.newFixedThreadPool(5);
    }

    public static void shutdownThread() {
        cachePool.shutdownNow();
        cachePool = null;
    }

    public static void restoration() {
        shutdownThread();
        startThread();
    }

    public static void startSavePool(Thread thread) {
        if (savePool == null) {
            savePool = Executors.newFixedThreadPool(1);
        } else {
            savePool.execute(thread);
        }
    }

    public static void shutdownSavePool() {
        cachePool.shutdownNow();
        cachePool = null;
    }
}
